package action.checksubmit;

import java.util.ArrayList;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;

import model.Work;
import model.submitState;

import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.Result;

import service.queryWorkService;
import service.querysubmitService;

import com.opensymphony.xwork2.ActionSupport;

@Namespace("")
@Action(
	value="checksubmit",
	results={
			@Result(name="success",location="/WEB-INF/submitState.jsp")
	}		
)
public class checksubmitState extends ActionSupport{
	
	public String execute() throws Exception { 
		HttpServletRequest request=ServletActionContext.getRequest();
		ServletContext application=request.getServletContext();
		String schoolyear=(String) application.getAttribute("schoolyear");
		queryWorkService  qws=new queryWorkService();
		querysubmitService qss=new querysubmitService();
		
		ArrayList<Work> worklist=qws.queryAllWork();
		ArrayList<submitState> submitstatelist=new ArrayList<submitState>();
		for(Work w : worklist){
			int work_id=w.getWork_id();
            submitState state=qss.querysubmitState(work_id,schoolyear);
			submitstatelist.add(state);
		}
		request.setAttribute("submitstatelist", submitstatelist);
		return SUCCESS;
	}

}

